<%@ page import="java.util.HashMap,common.CommonUtil,java.util.*,common.*" contentType="text/html; charset=utf-8" %>

<%
UserSession userSession = (UserSession)session.getAttribute("user"); 

String login_id = null;
String user_id = null;

if(userSession!= null){
	login_id = userSession.getLogin_id();
	user_id = userSession.getUser_id();
}

String cate_code = CommonUtil.nvl(request.getParameter("cate_code"));

%>
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script language='javascript' src="/js/ajaxutil.js"></script>
<script>

//xml 요청
function getXMLHTTPRequest() {
try {
  req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    } 
  } 
}
return req;
}


function get_prepexam_chk_request(exam_num,cate_code){
  
  var http = getXMLHTTPRequest();
  var myurl = '/speaking.pb?gubun=prepexam&cmd=id_chk&num='+exam_num+'&code='+cate_code;
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"&rand="+myRand;  
  http.open("get", modurl, false);
  //http.onreadystatechange = useHttpResponse;
  http.send(null);
  if (http.readyState == 4) {
    return trim(http.responseText);
  }else{
   return "";
  }
} 	

function trim(str){
	str = str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
}

function get_prepexam_chk(){
	var exam_num = document.mainform.exam_num.value;
	var cate_code = document.mainform.cate_code.value;
	if(exam_num == ''){
		alert('문제번호 를 입력해주세요');
		document.mainform.exam_num.focus();
		return;
	}
	
	if(cate_code == ''){
		alert('카테고리를 선택해주세요');
		document.mainform.cate_code.focus();
		return;
	}
	
	var id_chk_cnt = get_prepexam_chk_request(exam_num,cate_code);
	
	if(id_chk_cnt==0){
		document.mainform.id_chk.value='Y';
		alert('사용하실 수 있는 문제번호 입니다');
	}else{
		document.mainform.id_chk.value='N';
		alert('사용하실 수 없는 문제번호 입니다');
		document.mainform.exam_num.focus();
		document.mainform.exam_num.value='';
	}
}

function go_input(){
	var frm = document.mainform;	
	
	if(frm.id_chk.value=='N'){
		alert('문제 중복체크 해주세요');
		frm.exam_num.focus();
		return;
	}
	
	if(frm.exam_num.value==''){
		alert('문제번호를 입력 해주세요');
		frm.exam_num.focus();
		return;
	}
	if(frm.part_num.value==''){
		alert('파트를 입력 해주세요');
		frm.part_num.focus();
		return;
	}
	if(frm.cate_code.value==''){
		alert('카테고리를 선택 해주세요');
		frm.cate_code.focus();
		return;
	}
	
	if(isNaN(frm.exam_num.value)){
		alert('문제번호를  정수로 입력하세요.');
		frm.exam_num.focus();
		return;
	}
	
	if(isNaN(frm.part_num.value)){
		alert('파트를  정수로 입력하세요.');
		frm.part_num.focus();
		return;
	}
	
	if(isNaN(frm.ready_time.value) && frm.ready_time.value!=''){
		alert('준비시간  정수로 입력하세요.');
		frm.ready_time.focus();
		return;
	}
	if(isNaN(frm.response_time.value)  && frm.response_time.value!=''){
		alert('응답시간  정수로 입력하세요.');
		frm.response_time.focus();
		return;
	}
	/*
	if(frm.attachFile_1.value==''){
		alert('지문음성을 등록 해주세요');
		frm.attachFile_1.focus();
		return;
	}
	if(frm.attachFile_3.value==''){
		alert('모범답안을 등록 해주세요');
		frm.attachFile_3.focus();
		return;
	}
	*/
	
	//frm.cmd.value='prepexam_insert';
	frm.action = '/speaking.pb?cmd=prepexam_insert';
	frm.target= 'hidden_frm';              
	frm.submit();	
}

function go_prepexam(){
	
	var frm = document.moveform;	
	frm.cmd.value='prepexam_main';
	frm.action = '/speaking.pb';
	frm.target= '_self';              
	frm.submit();
	
}

function init_prepexam(){
	form = document.mainform;
	setSPSelect(form.cate_code,'<%=cate_code%>', '카테고리선택', 'prepcate');
	
    
}

function go_preview(){
	var popleft = (screen.width - 1000)/2;
	var poptop = (screen.height - 300)/2;
	var url="/jsp/sp_sp1102_preview.jsp";
	var open_preview = window.open(url,'preview','width=1000,height=300,resizable=yes,scrollbars=yes,top='+poptop+',left='+popleft);
	open_preview.focus();
}

function go_exam_preview_frm(){
	
	var url="/jsp/sp_sp1102_exam_preview_frm.jsp";
	
	exam_preview.location.href = url;
}

function go_answer_preview_frm(){
	
	var url="/jsp/sp_sp1102_answer_preview_frm.jsp";
	answer_preview.location.href = url;
}

window.onload = init_prepexam;
</script>

<jsp:include page="/jsp/common/top.jsp"></jsp:include>
<jsp:include page="/jsp/common/submenu.jsp"><jsp:param name="submenu_id" value="cate_main" /><jsp:param name="submenu_idx" value="2" /></jsp:include>

<form name="mainform"  method="post" action = "/speaking.pb" enctype= "multipart/form-data">
	<div id="bodyContainer">
        <div id="contents">
          <jsp:include page="/jsp/common/submenu_list.jsp"><jsp:param name="submenu_id" value="prepexam_main" /><jsp:param name="submenu_idx" value="2" /></jsp:include>
          
          
          <div class="boxContainer">
            <dl title="Speaking Test Prep  문제 등록">
              <dt>Speaking Test Prep  문제 등록</dt>
            </dl>
            <table class="setupTb">
              <tr>
                <th>카테고리</th>
                <td><select name="cate_code" id="cate_code" >
                  <option value=''>카테고리</option>                 
                </select></td>
              </tr>
              
              <!--  
              <tr>
                <th>파트</th>
                <td><input name="part_num" type="text" id="part_num" style="width:100px" />파트</td>
              </tr>
              -->
              
              <tr>
                <th>문제번호</th>
                <td><input name="exam_num" type="text" id="exam_num" style="width:100px" />번 &nbsp;&nbsp;&nbsp;<a href="#" onclick="get_prepexam_chk()"><input type="button" value="중복체크" style="width:100px; height:20px"></a></td> 
              </tr>
              
              
              
              <tr>
                <th>지문음성 등록</th>
                <td><input type="file" name="attachFile_1" id="attachFile_1" style="width:200px"/>
                </td>
              </tr>
              
              
              <tr>
                <th>문제내용</th>
                <td><textarea name="cont" rows="5" id="cont" style="width:680px" onkeydown="go_exam_preview_frm()"></textarea>
                <br>
                <br>
                
                <!-- <a href="#" onclick="go_preview()"><input type="button" value="미리보기" style="width:100px; height:20px" ></a>
                 -->
                 
                <b>미리보기</b>
                <br>
                <iframe name='exam_preview'  width='700' height='170' SCROLLING='AUTO' frameborder='0'></iframe>
                <script>go_exam_preview_frm()</script>
                </td>
              </tr>
              
              <tr>
                <th>모범답안음성 등록</th>
                <td><input type="file" name="attachFile_2" id="attachFile_2" style="width:200px"/>
                  </td>
              </tr>
              <tr>
                <th>모범답안내용 등록</th>
                <td><textarea name="answer_cont" rows="5" id="answer_cont" style="width:680px" onkeydown="go_answer_preview_frm()"></textarea>
                <br>
                <b>미리보기</b>
                <br>
                <iframe name='answer_preview'  width='700' height='170' SCROLLING='AUTO' frameborder='0'></iframe>
                <script>go_answer_preview_frm()</script>
                </td>
              </tr>
              
              <tr>
                <th>상태</th>
                <td><input type="radio" name="use_yn" id="use_yn" value="Y" checked/><span class="boldText">노출</span><input type="radio" name="use_yn" id="use_yn" value="N" /><span class="boldText">비노출</span></td>
              </tr>
              <!--  
              <tr>
                <th>준비시간 사용</th>
                <td><input type="radio" name="ready_yn" id="ready_yn" value="Y" checked/><span class="boldText">사용</span><input type="radio" name="ready_yn" id="ready_yn" value="N" /><span class="boldText">사용안함</span></td>
              </tr>
              <tr>
                <th>준비시간</th>
                <td><input name="ready_time" type="text" id="ready_time" style="width:100px" value='0'/>초</td>
              </tr>
              
              <tr>
                <th>응답시간 사용</th>
                <td><input type="radio" name="response_yn" id="response_yn" value="Y" checked/><span class="boldText">사용</span><input type="radio" name="response_yn" id="response_yn" value="N" /><span class="boldText">사용안함</span></td>
              </tr>
              <tr>
                <th>응답시간</th>
                <td><input name="response_time" type="text" id="response_time" style="width:100px" value='0'/>초</td>
              </tr>
              -->
                                      
            </table>
            <p><a href="#" onclick="go_input()"><img src="img/btn_regist.gif" alt="등록" width="49" height="20" /></a> <a href="#" onclick="go_prepexam()"><img src="img/btn_list.gif" alt="목록" width="49" height="20" /></a> </p>
            
          </div>
          
        </div>
      </div>


<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">
<input type="hidden" name="id_chk" value="N">
</form>

<form name="moveform"  method="post" action = "/speaking.pb" >
<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">
<input type="hidden" name="cate_code" value="<%=cate_code %>">
</form>
<iframe name='hidden_frm'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>
<jsp:include page="/jsp/common/footer.jsp"></jsp:include>
<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
